package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivityGoodDetail;
import nero.yncc.com.createart.bean.BeanArticle;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.utils.ImageUtils;

/**
 * Created by nero on 17-6-21.
 */

public class AdapterIndexFound extends RecyclerView.Adapter<AdapterIndexFound.Holder> {


    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LinearLayout.inflate(context, R.layout.adapter_index_found, null);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        BeanArticle bean = arrayList.get(position);
        holder.tv_title.setText(TextUtils.isEmpty(bean.getTitle()) ? context.getResources().getString(R.string.notitle) : bean.getTitle());
        holder.tv_content.setText(TextUtils.isEmpty(bean.getTitle()) ? context.getResources().getString(R.string.noContent) : bean.getTitle());
        holder.ll_root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, ActivityGoodDetail.class);
                context.startActivity(intent);
            }
        });
        ImageUtils.BindImage(context,holder.iv_image,bean.getThumb(),1);
    }


    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    Context context;
    ArrayList<BeanArticle> arrayList;

    public AdapterIndexFound(Context context, ArrayList<BeanArticle> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    class Holder extends RecyclerView.ViewHolder {
        public Holder(View itemView) {
            super(itemView);
            iv_image = itemView.findViewById(R.id.iv_image);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_content = itemView.findViewById(R.id.tv_content);
            ll_root = itemView.findViewById(R.id.ll_root);
        }

        final ImageView iv_image;
        final TextView tv_title, tv_content;
        final LinearLayout ll_root;
    }
}
